package com.hailiao.beidou.message.ui.page.home

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.d10ng.compose.model.UiViewModelManager
import com.d10ng.compose.ui.dialog.builder.ConfirmDialogBuilder
import com.hailiao.beidou.message.data.chat.ChatRepository
import com.hailiao.beidou.message.data.db.entity.ChatEntity
import kotlinx.coroutines.launch

/**
 * 首页
 * @Author d10ng
 * @Date 2024/3/1 17:03
 */
class HomeScreenViewModel: ViewModel() {

    // 对话框列表数据
    val dataFlow = ChatRepository.pageDataFlow

    /**
     * 点击删除对话
     * @param chat ChatEntity
     */
    fun onClickDeleteChat(chat: ChatEntity) {
        UiViewModelManager.showDialog(ConfirmDialogBuilder(
            content = "确定删除对话吗？",
            onConfirmClick = {
                viewModelScope.launch {
                    UiViewModelManager.showLoading()
                    ChatRepository.delete(chat)
                    UiViewModelManager.hideLoading()
                }
                true
            }
        ))
    }
}